#include <iostream>
#include <cstdio>

#include "ProtoManager.h"
#include "utils/logger.h"

int main(int argc, char* argv[]) {
    if (argc != 3) {
        std::cout << "Usage: ./main <path-to-query> <number-of-workers>" << std::endl;
        return 1;
    }

    Operation o;
    int file = open(argv[1], O_RDONLY);
    CHECK(file != -1, "Error opening file");
    google::protobuf::io::FileInputStream input(file);
    google::protobuf::TextFormat::Parse(&input, &o);

    ProtoManager pm(o, atoi(argv[2]));
    std::vector<internal::TaskList*> stripes = pm.getStripes();

    for (int i = 0; i < stripes.size(); ++i) {
        std::string out;
        google::protobuf::TextFormat::PrintToString(*stripes[i], &out);
        std::cout << "Worker ID: " << i+1 << std::endl << out << std::endl;
    }

    internal::InputOperation* io = pm.getResultTypes(o);
    for (int i = 0; i < io->type_size(); ++i) {
        std::cout << io->type(i) << std::endl;
    }

    return 0;
}
